var fs = require('fs');
var path = require('path');

var dirname = __dirname;
var index = dirname.lastIndexOf('/');
dirname = dirname.substring(0, index);

module.exports = [
    {
        entry: "./Index.js",
        output: {
            filename: "bundle.js",
            path: path.resolve(__dirname, "public")
        },
        module: {
            loaders: [
                {
                    test: /\.js$/,
                    exclude: /node_modules/,
                    loader: "babel-loader"
                }
            ]
        }
    },
    {
        entry: "./Server.js",
        output: {
            filename: "Server.bundle.js"
        },

        target: 'node',

        // keep node_module paths out of the bundle
        externals: fs.readdirSync(path.resolve(dirname, 'node_modules')).concat([
            'react-dom/server', 'react/addons',
        ]).reduce(function (ext, mod) {
            ext[mod] = 'commonjs ' + mod
            return ext
        }, {}),

        node: {
            __filename: true,
            __dirname: true
        },

        module: {
            loaders: [
                {test: /\.js$/, loader: 'babel-loader?presets[]=es2015&presets[]=react'}
            ]
        }
    }
]